package com.gxa.service.impl;

import com.gxa.mapper.CustomerMapper;
import com.gxa.service.CustomerService;
import com.gxa.pojo.Customer;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Data
@NoArgsConstructor
@Service("CustomerService")
public class CustomerServiceImpl implements CustomerService {


    @Autowired
    CustomerMapper customerMapper;

    @Override
    @Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.REQUIRED,rollbackFor = {Throwable.class})
    public int insert(Map map) {

        return customerMapper.insert(map);
    }

    @Override
    @Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.REQUIRED,rollbackFor = {Throwable.class})
    public int insertSelective(Map map) {
        return customerMapper.insertSelective(map);
    }

    @Override
    @Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.SUPPORTS,rollbackFor = {Throwable.class})
    public Integer findAllCustomer() {
        return customerMapper.findAllCustomer();
    }

    @Override
    @Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.SUPPORTS,rollbackFor = {Throwable.class})
    public List<Customer> findAllCustomerByPage(Integer start, Integer pageSize) {
        return customerMapper.findAllCustomerByPage(start,pageSize);
    }

    @Override
    @Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.REQUIRED,rollbackFor = {Throwable.class})
    public int deleteByPrimaryKey(Integer id) {
        return customerMapper.deleteByPrimaryKey(id);
    }

    @Override
    @Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.REQUIRED,rollbackFor = {Throwable.class})
    public int deleteBatch(List<Integer> list) {
        return customerMapper.deleteBatch(list);
    }

    // 修改选择的
    @Override
    @Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.REQUIRED,rollbackFor = {Throwable.class})
    public int updateByPrimaryKeySelective(Map map) {
        return customerMapper.updateByPrimaryKeySelective(map);
    }

    // 多参数模糊查询
    @Override
    @Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.SUPPORTS,rollbackFor = {Throwable.class})
    public List<Map<String, Object>> findBySelect(Map map) {
        return customerMapper.findBySelect(map);
    }

    // 计算查询条数
    @Override
    @Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.SUPPORTS,rollbackFor = {Throwable.class})
    public Integer countFindCustomer(Map<String,Object> map) {
        return customerMapper.countFindCustomer(map);
    }


}
